import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @ClassName: ThreadToolExceptionTest
 * @Author: chenyu
 * @Date: 2025/3/21 13:55
 */
public class ThreadToolExceptionTest {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 200, 30,
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(500), new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread t, Throwable e) {
                        System.out.println("出错了");
                    }
                });
                return thread;
            }
        });

        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("提交任务......");
                throw new NullPointerException();
            }
        });
    }
}
